/*
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-04-24 23:03:01
 * @LastEditTime: 2021-04-24 23:11:51
 */

class FileListPlugin {
    constructor({ filename }) {
        this.filename = filename;
    }

    apply(compiler) {
        compiler.hooks.emit.tapAsync('FileListPlugin', (compilation) => {
            console.log(compilation.assets,"xx")
            let assets = compilation.assets;
            let content = `## 文件名    资源大小`;

            Object.entries(assets).forEach(([filename, statObj]) => {
                content += `- ${filename}   ${statObj.size}`;
            });
            assets[this.filename] = {
                source() {
                    return content
                },

                size() {
                    return content.length;
                }
            }
        });
    }

}

module.exports = FileListPlugin;
